package com.contract.commonlib.refresh

import android.content.Context
import android.util.AttributeSet
import android.widget.LinearLayout
import android.widget.TextView
import android.widget.RelativeLayout
import android.view.LayoutInflater
import android.widget.ImageView
import com.contract.commonlib.R
import com.contract.commonlib.refresh.NoMoreDataFootView

/**
 * @author zhengjun
 * @desc 上拉加载更多  当无更多数据，没有数据时显示的footview
 * @create at 2018/8/24 16:17
 */
class NoMoreDataFootView : LinearLayout {
    var tv_foot: TextView? = null
    var iv_empty: ImageView? = null
    var rlParent: RelativeLayout? = null

    constructor(context: Context) : super(context) {
        initView(context)
    }

    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
        initView(context)
    }

    private fun initView(context: Context) {
        LayoutInflater.from(context).inflate(R.layout.footview_nomore_data, this, true)
        tv_foot = findViewById(R.id.tv_foot)
        iv_empty = findViewById(R.id.iv_empty)
        rlParent = findViewById(R.id.rlParent)
    }

    var state = 0
    fun getFootViewState(): Int {
        return state;
    }

    /**
     * @desc 设置没有内容时显示的文案
     * @author zhengjun
     * @created at 2018/9/6 10:11
     */
    fun setFootText(text: String?) {
        tv_foot!!.text = text
    }

    //设置背景颜色
    fun setCustomBackGroudnColor(colorId: Int) {
        rlParent!!.setBackgroundColor(resources.getColor(colorId))
    }

    fun footViewState(state: Int) {
        this.state = state;
        when (state) {
            FOOT_NO_MORE -> {
                tv_foot!!.visibility = VISIBLE
                tv_foot!!.text = "-没有更多了-"
                iv_empty!!.visibility = GONE
            }
            FOOT_LOAD_ERROR -> {
                tv_foot!!.visibility = VISIBLE
                iv_empty!!.visibility = VISIBLE
                iv_empty!!.setImageResource(R.mipmap.default_pic_nodatas)
                tv_foot!!.text = "加载出错，请下拉刷新页面"
            }
            FOOT_HIDE -> {
                tv_foot!!.visibility = GONE
                iv_empty!!.visibility = GONE
            }
            FOOT_NO_DATA -> {
                tv_foot!!.visibility = VISIBLE
                iv_empty!!.visibility = VISIBLE
                iv_empty!!.setImageResource(R.mipmap.default_pic_nodatas)
                tv_foot!!.text = "暂无数据"
            }
        }
    }

    companion object {
        const val FOOT_NO_MORE = 1 //显示底部footview 显示文案为 已经到底了
        const val FOOT_NO_DATA = 2 //无数据
        const val FOOT_HIDE = 3 //隐藏
        const val FOOT_LOAD_ERROR = 4 //加载出错
    }
}